
$(document).ready(function(){
	var a = $("#abc").val().split("-");

	var sheng = $("#province")[0];
	var shi   = $("#city")[0];
	var qu    = $("#country")[0];
	var aArr, bArr, cArr;
	
	//fetch("common/area").then(r => r.json()).then(data=>{console.log(data);aArr=data})
    
	$.ajax({
		async: false, 
		url: "common/area", 
		success: function(area) { aArr = area }
	})
	
	aArr.forEach(e => sheng.options.add(new Option(e.text, e.id, a[0]==e.id, a[0]==e.id)));
	
	sheng.onchange = function () {
	    $('#city option').not('option:first').remove(); 
	    $('#country option').not('option:first').remove(); 
	    bArr = aArr.find(e => e.id == this.value).children;
	    bArr.forEach(e => shi.options.add(new Option(e.text, e.id, a[1]==e.id, a[1]==e.id)));
	}
	
	shi.onchange = function () {
	    $('#country option').not('option:first').remove(); 
	    cArr = bArr.find(e => e.id == this.value).children;
	    cArr.forEach(e => qu.options.add(new Option(e.text, e.id, a[2]==e.id, a[2]==e.id)));
	}
	if(a[0]!='0')$(sheng).change();
	if(a[1]!='0')$(shi).change();
})